package com.idheima.zuoye.zuoye2;

import java.util.Scanner;

public class Test {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入支付方式：[WeChat,Ali,Bank]");
        String type = sc.next();
        System.out.println("请输入支付金额：");
        int money = sc.nextInt();
        // 通过工厂类中的方法，获取支付对象，并调用支付方法完成支付
        // 【此处完成代码】

        Payment payment = Factory.getInstance(type);
        payment.pay(money);
    }

}



// 工厂类，专门负责创建对象
//
class Factory{
    public static Payment getInstance(String type){
        if(!(type.equals("wx")||type.equals("ali")||type.equals("bank"))){
            return null;
        }

        Payment  payment=null;
        switch (type){
            case"wx":
                payment = new WechatPay();
                break;
            case"ali":
                payment = new AliPay();
                break;
            case"bank":
                payment = new BankPay();
                break;
        }
        return payment;
    }
}








